package blog.farb.top.springbootforredis.controller;

import blog.farb.top.springbootforredis.service.SellService;
import blog.farb.top.springbootforredis.utils.BenchMarkTest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class BuyController {

    private final SellService sellService;

    public BuyController(SellService sellService) {
        this.sellService = sellService;
    }

    @GetMapping("/quickBuy/{item}/{buyer}")
    public String quickBuy(@PathVariable String item, @PathVariable String buyer) {
        String res = sellService.quickBuy(item, buyer);
        return res.equals("1") ? buyer + " Success" : buyer + " Fail";
    }

    @GetMapping("/quickBuy/benchMark")
    public String benchMark() {
        for (int i = 0; i < 15; i++) {
            new BenchMarkTest().start();
        }
        return "Success";
    }
}
